package com.kfm.base.thread.day01;

import java.util.Arrays;

public class Exer03 {

    public static void main(String[] args) {
        int[] nums = {5, 3, 1, 8, 9, 4, 6, 7, 2};
        // 0, 2  3, 5   6, 8

        Thread t1 = new Thread(new MyRunnable2(nums, 0, 3));
        Thread t2 = new Thread(new MyRunnable2(nums, 3, 6));
        Thread t3 = new Thread(new MyRunnable2(nums, 6, 9));

        t1.start();
        t2.start();
        t3.start();

        try {
            // 等 t1 线程完成
            t1.join();
            // 等 t2 线程完成
            t2.join();
            // 等 t3 线程完成
            t3.join();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        System.out.println(Arrays.toString(nums));

    }
}

class MyRunnable2 implements Runnable {

    private int[] num;

    private int start;

    private int end;

    public MyRunnable2(int[] num, int start, int end) {
        this.num = num;
        this.start = start;
        this.end = end;
    }

    @Override
    public void run() {
        Arrays.sort(num, start, end);
    }

    public int getSum(){
        return 0;
    }
}
